<?php

namespace app\api\model;

use think\Model;

/**
 * Game
 */
class Game extends Model
{
    // 表名
    protected $name = 'game';


    public function getGameList($params){
        $member_id = $params['member_id'] ?? 0;
        $list = self::where(['status' => 1])
            ->order('weigh asc')
            ->field('id,image,name,type')
            ->select();

        $gameLog = (new GameLog())
            ->where(['member_id' => $member_id])
            ->field('count(game_id) as count,game_id')
            ->group('game_id')->select()->toArray();
        $gameNums = array_column($gameLog,'count','game_id');
        foreach ($list as $key=>&$val){
            $list[$key]['image'] =env('domain.image_url').$val['image'];
            $val['status'] = 1;
            $val['nums'] = $gameNums[$val['id']] ?? 0;
        }

        return api_message($list);
    }

}